package com.haizhi.crm.common.util;

import com.haizhi.crm.common.constant.EntityType;
import com.haizhi.crm.common.model.CommonEntityDto;
import com.haizhi.crm.common.model.PageResponse;
import com.haizhi.crm.common.model.Response;
import org.apache.shiro.SecurityUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by haizhi on 2018/3/5.
 */
public class CommonUtils {

    public static Long getUserID() {
        return (Long) SecurityUtils.getSubject().getSession().getAttribute("userID" );
    }


    public static void mapResp(Map data, PageResponse resp) {
        if (data != null) {
            Integer total = (Integer) data.get("total" );
            Integer pageNo = (Integer) data.get("pageNo" );
            Integer pageSize = (Integer) data.get("pageSize" );

            if (total != null && pageNo != null && pageSize != null) {
                resp.setPageInfo(total, pageNo, pageSize);
            }
        }

        mapUIConfig(resp);
    }

    private static void mapUIConfig(Response resp) {
        Object searchRes = resp.getPayload();
        if (searchRes != null && searchRes instanceof CommonEntityDto) {
            CommonEntityDto target = (CommonEntityDto) searchRes;

            Map customerUiConfig = new HashMap();
            customerUiConfig.put("cn_name", "中文名称" );
            customerUiConfig.put("name", "客户名称" );
            customerUiConfig.put("legal_representative", "公司法人" );
            customerUiConfig.put("reg_capital", "注册资本" );
            customerUiConfig.put("reg_date", "注册日期" );
            customerUiConfig.put("reg_address", "注册地址" );
            customerUiConfig.put("management_scope", "经营范围" );
            customerUiConfig.put("credit_class", "信用等级" );
            customerUiConfig.put("logo_uri", "公司官网" );
            customerUiConfig.put("industry", "行业" );
            customerUiConfig.put("phone", "联系电话" );
            customerUiConfig.put("margin_contribution_index", "贡献指数" );
            customerUiConfig.put("coorperation_length", "合作年限" );
            customerUiConfig.put("stock_code", "股票代码" );
            customerUiConfig.put("service_scale_index", "业务规模指数" );
            customerUiConfig.put("social_credit_code", "统一社会信用代码" );

            Map innerUI = new HashMap();
            innerUI.put("title", "标题" );
            innerUI.put("person", "姓名" );
            innerUI.put("account", "账号" );
            innerUI.put("content", "内容" );
            innerUI.put("type", "类型" );
            innerUI.put("push_time", "日期" );

            Map outterUI = new HashMap();
            outterUI.put("title", "标题" );
            outterUI.put("type", "类型" );
            outterUI.put("push_time", "日期" );
            outterUI.put("type", "类型" );
            outterUI.put("company", "公司" );
            outterUI.put("desc", "描述" );

            Map visitUI = new HashMap();
            visitUI.put("title", "标题" );
            visitUI.put("manager_list", "客户经理" );
            visitUI.put("bank", "所属支行" );
            visitUI.put("visit_time", "拜访时间" );

            Map productUI = new HashMap();
            productUI.put("product_code", "产品代码" );
            productUI.put("name", "产品名称" );
            productUI.put("product_term", "产品期限" );
            productUI.put("distribution_scale", "发行规模" );
            productUI.put("scale_time", "销售时间" );
            productUI.put("min_invest", "最小投资" );

            Map uiConfig = new HashMap();
            uiConfig.put(EntityType.COUSTOMER.getValue(), customerUiConfig);
            uiConfig.put(EntityType.PRODUCT.getValue(), productUI);
            uiConfig.put(EntityType.EVENT_INNER.getValue(), innerUI);
            uiConfig.put(EntityType.EVENT_OUTTER.getValue(), outterUI);
            uiConfig.put(EntityType.VISIT_RECORD.getValue(), visitUI);

            target.setUiConfig(uiConfig);
        }

    }
}
